package chaoyue.study.controller;

import chaoyue.study.domain.LoginUserParam;
import chaoyue.study.service.LoginService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 自定义登录接口
 * 注意：登录接口是不需要认证的，需要在过滤器中进行放行
 */
@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/user/login")
    public String login(@RequestBody LoginUserParam loginUser) {
        return loginService.login(loginUser);
    }

    @PostMapping("/user/logout")
    public String logout(HttpServletRequest request) {
        String token = request.getHeader("token");
        return loginService.logout(token);
    }
}
